/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package demo.collection;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Scanner;

/**
 *
 * @author VANDH
 */
public class DemoMap {

    private static HashMap hotelMap = new HashMap();
    private static Scanner keyboard = new Scanner(System.in);

    public static void main(String[] args) {
        int choice;

        do {
            System.out.println("1. Thêm một khách sạn");
            System.out.println("2. Xóa khách sạn theo tên");
            System.out.println("3. In ra danh sách");
            System.out.println("4. Thoát");
            choice = keyboard.nextInt();

            switch (choice) {
                case 1:
                    addHotel();
                    break;
                case 2:
                    removeHotel();
                    break;
                case 3:
                    listAllHotel();
                    break;

            }
        } while (choice != 4);
    }

    private static void addHotel() {
        Hotel h;
        do {
            System.out.printf("Hotel %d : ", hotelMap.size() + 1);
            h = new Hotel();
            h.inputHotel();

            if (!h.hotelName.equals("1")) {
                hotelMap.put(h.hotelName, h);
            }
        } while (!"1".equals(h.hotelName));
    }

    private static void removeHotel() {
        System.out.println("Khách sạn muốn xóa : ");
        String name = keyboard.next();

        Iterator i = hotelMap.entrySet().iterator();
        while (i.hasNext()) {
            Map.Entry entry = (Map.Entry) i.next();
            Hotel h = (Hotel) entry.getValue();

            if (h.hotelName.equals(name)) {
                i.remove();
            }
        }
    }

    private static void listAllHotel() {
        for (Object k : hotelMap.keySet()) {
            Hotel h = (Hotel) hotelMap.get(k);
            System.out.println(h.toString());
        }
    }
}
